<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="css/aui.css">
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" src="js/init.js"></script>
    <title>登录</title>
    <style>
        body{
            background: url("img/login_bg.jpg") center top;
            background-size: cover;
        }
    </style>
</head>
<body class="flex">

<ul class="col-8 auto">
    <li class="mar-b-2 bg-white border-radius-1 hidden flex flex-stretch">
        <p class="col-15 bg-gray-l flex">
            <img class="col-3 auto" src="img/login1.png" alt="">
        </p>
        <input id="account" class="f1 pad-2" type="text" placeholder="请输入账号">
    </li>
    <li class="mar-b-2 bg-white border-radius-1 hidden flex flex-stretch">
        <p class="col-15 bg-gray-l flex">
            <img class="col-3 auto" src="img/login2.png" alt="">
        </p>
        <input id="password" class="f1 pad-2" type="password" placeholder="请输入密码">
    </li>
    <!--<li class="mar-b-2 border-radius-1 hidden flex flex-stretch">
        <p class="col-15 bg-gray-l flex">
            <img class="col-3 auto" src="img/login3.png" alt="">
        </p>
        <input class="f1 pad-2 bg-white" type="text" placeholder="请输入验证码">
        <span></span>
    </li>-->

    <li id="login" class="bg-green border-radius-1 center color-white pad-2-3">登 录</li>
    <li class="color-white font25 pad-t-2">
        <a href="forgetPwd.html" class="color-white">忘记密码</a>
        <span class="fr" onclick="download()">客户端下载</span>
    </li>
</ul>

<script>

    var lock = true;
    localStorage.user_id = '';
    localStorage.token = '';
    $("#login").click(function () {

            var account = $("#account").val();
            var passward = $("#password").val();

            if(!account || !passward){
                toast('请填写完整信息');

            }else{

                if(lock) {
                    lock = false;
                    var data = {
                        account: account,
                        password: passward,
                    };

                    $.ajax({
                        type: 'post',
                        dataType: 'json',
                        url: hostUrl + 'index/login/login',
                        data: data,
                        success: res => {
                            toast(res.msg);
                            console.log(res);
                            if(res.status == 1){
                                localStorage.user_id = res.data.id;
                                localStorage.token = res.data.token;
                                setTimeout(function () {
                                    window.location.href = 'index.html';
                                    lock = true;
                                },2000)
                            }else{
                                lock = true;
                            }
                        },
                        error: function (err) {
                            console.log(err);
                            console.log(err.responseText);
                            console.log(err.state);
                            console.log(err.statusText);
                            lock = true;
                        }
                    })

                    /*new AjaxRequest({
                        type: 'post',
                        dataType: 'html',
                        url: hostUrl + 'index/login/login',
                        data: data,
                        callback: res => {
                            toast(res.msg);
                            alert('bbbb');
                            console.log(res)
                            if(res.status == 1){
                                localStorage.user_id = res.data.id;
                                localStorage.token = res.data.token;
                                setTimeout(function () {
                                    // window.location.href = 'index.html';
                                },2000)
                            }
                        },
                        error : (err) => {
                            console.log(err)
                            console.log(err.responseText)
                            console.log(err.state)
                            console.log(err.statusText)
                        }
                    })*/

                }

            }

    });

    // 客户端下载
    var u = navigator.userAgent;
    var device = '';
    if(u.indexOf('Android') > -1 || u.indexOf('Linux') > -1){
        device = 'Android';
    }
    if(u.indexOf('iPhone') > -1 ){
        device = 'iPhone';
    }

    function download() {
        var data={};
        $.ajax({
            type: 'get',
            dataType: 'json',
            url: hostUrl + 'index/Login/geturl',
            data: data,
            success: res => {
                console.log(res);
                if(res.status == 1){

                    console.log(device);

                    if(device == 'Android'){

                        if(res.data.android){
                            location.href = res.data.android;
                        }else{
                            toast('暂无Android下载');
                        }

                    }
                    if(device == 'iPhone'){

                        if(res.data.ios){
                            location.href = res.data.ios;
                        }else{
                            toast('暂无ios下载');
                        }

                    }

                }
            },
            error: function (err) {

            }
        })
    }



</script>

</body>
</html>